<template>
	<view class="content">
		<view class="head">
			<!-- <view class="head-text" @tap="openshare(0, 'center')">邀约客户专属链接</view> -->
			<!-- <navigator class="head-text" url="../index/index?activity_id=">邀约客户专属链接</navigator> -->
			<view class="head-text" @click="index">邀约客户专属链接</view>
		</view>

		<!-- 员工邀约列表 -->
		<!-- <staffInvList :invite_list_data="invite_list_data" :length="invite_list_data.length" :staff_name="staff_info_data.name" :scrollH="scrollH" :status="status" style="margin-bottom: 140rpx;"/> -->
		
		<invlist :invite_list_data="invite_list_data" :length="invite_list_data.length" :staff_name="staff_info_data.name" :scrollH="scrollH" :status="status" v-on:check="check" style="margin-bottom: 140rpx;"/>
		
		<!-- tabbar -->
		<staff-tab-bar :pagePath="'/pages/staff/invitation'" :activity_id="activity_id" :factory_id="factory_id" :staff_id="staff_id" />

		<view class="top" :style="{'display':(flag===true? 'block':'none')}">
			<uni-icons class="topc" type="arrowthinup" size="30" @click="top"></uni-icons>
		</view>
		
		
		<canvas class="canvas" canvas-id="qrcode" />
		<openAlert :BgColor="BgColor" :AlertClass="AlertClass" :AlertPosition="AlertPosition" closeBtn ref="openAlertshare">
			<view class="d-flex flex-column a-center">
				<text class="sharetext">长按图片,分享好友</text>
				<image :src="haibao_url" class="shareimg"></image>
			</view>
		</openAlert>

	</view>
</template>

<script>
	import uQRCode from '../../common/uqrcode.js'
	require('../../components/poster/poster_maker.js');
	import staffTabBar from '../../components/staff/staff_tabbar.vue'
	import uniIcons from '../../components/common/uni-icons/uni-icons.vue'
	import invlist from '../../components/staff/invlist.vue'

	export default {
		components: {
			staffTabBar,
			uniIcons,
			invlist,
		},
		data() {
			return {
				BgColor: '#838383',
				staff_info_data: {},
				activity_id: 0,
				factory_id: 0,
				staff_id: 0,
				AlertClass: 0,
				AlertPosition: '',
				staff: {
					username: '',
					userphone: '',
				},
				invite_list_data: [],
				haibao_url: '',
				factory_info_data: {},
				page: 1,
				flag: false,
				scrollH: 100,
				status: 'nomore',
				haibao_id: 0,
			};
		},
		onLoad(e) {
			console.log(e)
			this.staff_id = e.staff_id
			this.factory_id = e.factory_id
			this.activity_id = e.activity_id
			this.$comm.appLogin(user_info=>{
				this.my_staff_info()
				this.invite_list()
				this.factory_info()
				// this.get_scrollH()
				// this.get_activity()
			})
		},
		onPullDownRefresh() {
			this.loaddata()
		},
		onReachBottom() {
			// this.invite_list()
		},
		methods: {
			check:function(index) {
				this.$comm.request({
					url: 'api/staff_invite_check',
					method: 'POST',
					data: {
						invite_id: this.invite_list_data[index].id,
						fac_id: this.invite_list_data[index].fac_id,
					},
					success: (res) => {
						console.log(res)
						this.invite_list_data[index].is_check = 1
						// this.$set(this.invite_list_data[index],'is_check',1)
					},
				})
			},
			index() {
				uni.navigateTo({
					url: '../index/index?activity_id=' + this.activity_id + '&staff_id=' + this.staff_id
				})
			},
			get_activity() {
				var id = this.activity_id;
				this.$comm.request({
					url: 'api/activity_detail?activity_id=' + id,
					method: 'GET',
					// data: {
					// 	activity_id: id
					// },
					success: res => {
						this.haibao_id = res.data.result.haibao_id
						console.log(res, this.haibao_id,999)
					}
				})
			},
			//获取邀约列表
			invite_list() {
				// if (this.status == 'nomore') {
				// 	return
				// }
				var id = this.factory_id
				this.$comm.request({
					url: 'api/invite_list?fac_id=' + id + '&activity_id=' + this.activity_id,
					method: 'GET',
					data: {
						// page: this.page++
					},
					success: res => {
						// this.invite_list_data = res.data.result
						console.log(res, 'api/invite_list')
						this.invite_list_data = res.data.result
						// this.invite_list_data = this.invite_list_data.concat(list)
						if (list.length < 10) {
							this.status = 'nomore'
						}
					}
				})
			},

			//获取员工自己的信息
			my_staff_info() {
				this.$comm.request({
					url: 'api/my_staff_info',
					method: 'GET',
					data: {
						fac_id: this.factory_id
					},
					success: res => {
						var res = res.data
						console.log(res)
						this.staff_info_data = res.result;
						// console.log(this.staff_info_data)
						this.staff.username = res.result.name;
						this.staff.userphone = res.result.tel;
						this.staff_id = res.result.id
					}
				})
			},

			loaddata() {
				this.page = 1
				this.status = 'more'
				this.invite_list_data = []
				this.invite_list()
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 1000);
			},

			get_scrollH() {
				//获取可视区域高度
				uni.getSystemInfo({
					success: (res) => {
						this.scrollH = res.windowHeight - uni.upx2px(345)
						// console.log(res.windowHeight, '可视区域高度',this.scrollH)
					}
				})
			},

			// 打开分享
			openshare(Class, Position) {
				this.$nextTick(function() {
					this.AlertClass = Class;
					this.AlertPosition = Position;
					this.$nextTick(function() {
						this.make();
						uni.showToast({
							icon: 'loading',
							duration: 450,
							title: '二维码生成中...',
						});
						setTimeout(() => {
							this.$refs.openAlertshare.Show();
						}, 500);
					});
				});
			},

			// 制作二维码
			make(id) {
				let name = this.staff_info_data.name
				let fname = this.factory_info_data.name
				uQRCode.make({
					canvasId: 'qrcode',
					componentInstance: this,
					text: this.$comm.app_config.share_url + '/index/index?activity_id=' + this.activity_id +'&factory_id=' + this.factory_id +'&staff_id=' + this.staff_id,
					// text: 'http://192.168.0.190:8080/bm/#/pages/index/index?activity_id=' + this.activity_id +'&factory_id=' + this.factory_id +'&staff_id=' + this.staff_id,
					size: 250,
					backgroundColor: '#FFFFFF',
					foregroundColor: '#000000',
					fileType: 'jpg',
					correctLevel: uQRCode.defaults.correctLevel,
					success: res => {
						postMaker(this.haibao_id, [res, name + '(' + fname + ')'], 500, url => {
							this.haibao_url = url;
						});
					}
				});
			},

			//获取商家信息
			factory_info(id) {
				this.$comm.request({
					url: 'api/my_factory_info?activity_id=' + this.activity_id,
					method: 'GET',
					success: res => {
						this.factory_info_data = res.data.result;
					}
				});
			},

			//回到顶部
			top() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			onPageScroll(e) { //根据距离顶部距离是否显示回到顶部按钮
				if (e.scrollTop > 600) { //当距离大于600时显示回到顶部按钮
					this.flag = true
				} else { //当距离小于600时显示回到顶部按钮
					this.flag = false
				}
			},
		}
	};
</script>

<style lang="scss" scoped>
	@import '@/common/main.css';
	@import  '@/common/zcm-main.css';
	
	page {
		background-color: #f1f1f1;
		font-size: 30rpx;
	}

	.head {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 30rpx;

		.head-text {
			color: #ffffff;
			line-height: 2.5;
			background-color: #475dfc;
			width: 400rpx;
			text-align: center;
			border-radius: 50rpx;
			// margin-top: 20rpx;
		}
	}

	.sharetext {
		color: #fff;
		font-size: 35rpx;
		margin-bottom: 10rpx;
	}

	.shareimg {
		border-radius: 20rpx;
		height: 950rpx;
		width: 580rpx;
	}

	.share-but {
		margin-top: 20rpx;
		margin-bottom: 20rpx;
		background-color: #475dfc;
		color: #ffffff;
		width: 500rpx;
	}

	.canvas {
		// background-color: #4CD964;
		width: 500rpx;
		height: 500rpx;
		position: fixed;
		right: 100vw;
		bottom: 100vh;
		z-index: -9999;
		opacity: 0;
	}

	.top {
		position: relative;
		display: none;
		/* 先将元素隐藏 */
	}

	.topc {
		position: fixed;
		right: 0;
		// background: #F0F0F0;
		bottom: 120rpx;
		right: 30rpx;
		background-color: #FFF;
		border: solid 2rpx #475dfc;
		border-radius: 100rpx;
		height: 80rpx;
		width: 80rpx;
		line-height: 80rpx;
	}
</style>
